import logging
import traceback


def common_assert(testcase, response, exp_status_code, exp_status, exp_desp):
    """
    :param testcase: 对象
    :param response: 响应结果
    :param exp_status_code: 预期响应状态码
    :param exp_status: 响应体status断言
    :param exp_desp: 响应体description断言
    """
    # 响应体字典格式
    res_dict = response.json()
    # 响应状态码断言
    testcase.assertEqual(exp_status_code, response.status_code)
    # 响应体status断言
    testcase.assertEqual(exp_status, res_dict['status'])
    # 响应体description断言
    testcase.assertIn(exp_desp, res_dict['description'])


def common_assert1(testcase, response, exp_status_code, exp_status, exp_desp, case_name):
    """

    :param testcase: self
    :param response: 响应数据
    :param exp_status_code: 预期响应状态码
    :param exp_status: 预期响应status
    :param exp_desp: 预期响应信息
    :param case_name: 用例名称
    """
    # 响应体字典格式
    res_dict = response.json()
    try:
        # 响应状态码断言
        testcase.assertEqual(exp_status_code, response.status_code)
        # 响应体status断言
        testcase.assertEqual(exp_status, res_dict['status'])
        # 响应体description断言
        testcase.assertIn(exp_desp, res_dict['description'])
    except:
        logging.error('用例执行失败：{}'.format(case_name))
        logging.error(traceback.format_exc())
